package com.zygh.interactiveplatform.module.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.interactiveplatform.common.constant.EmployeeResponseCodeConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.Operation;
import com.zygh.interactiveplatform.module.entity.Operation;
import com.zygh.interactiveplatform.module.entity.vo.OperationVo;
import com.zygh.interactiveplatform.module.mapper.OperationMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zygh.interactiveplatform.module.mapper.OperationMapper;
import jdk.nashorn.internal.runtime.regexp.joni.constants.OPCode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lee
 * @since 2021-01-29
 */
@Service
public class OperationService extends ServiceImpl<OperationMapper, Operation> {
    @Resource
    private OperationMapper operationMapper;

    public ResponseDTO addOperation(Operation operation) {
        int insert = operationMapper.insert(operation);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.ADD_EXIST);
    }

    public ResponseDTO updateOperation(Operation operation) {
        int insert = operationMapper.updateById(operation);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.UPDATE_EXIST);
    }

    public ResponseDTO deleteOperation(Integer id) {
        int insert = operationMapper.deleteById(id);
        if (insert > 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.DELETE_EXIST);
    }

    public ResponseDTO findOperationAll(Integer current, Integer size) {
        PageHelper.startPage(current, size);
        List<Operation> operations = operationMapper.selectList(null);
        if (operations != null) {
            PageInfo<Operation> pageInfo = new PageInfo<>(operations);
            return ResponseDTO.succData(pageInfo);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }

    public ResponseDTO findOperationLog(OperationVo operation) {
        PageHelper.startPage(operation.getCurrent(), operation.getSize());
        List<Operation> operations = operationMapper.findOperationLog(operation);
        if (operations != null) {
            PageInfo<Operation> pageInfo = new PageInfo<>(operations);
            return ResponseDTO.succData(pageInfo);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }

    public ResponseDTO eventStatistics() {
        List<Map> operations = operationMapper.eventStatistics();
        if (operations != null) {
            return ResponseDTO.succData(operations);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }

    public ResponseDTO eventLevel() {
        List<Map> operations = operationMapper.eventLevel();
        if (operations != null) {
            return ResponseDTO.succData(operations);
        }
        return ResponseDTO.wrap(EmployeeResponseCodeConst.EMPTY_INFORMATION_ERROR);
    }



}
